package com.success.system.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.success.system.domain.Tenant;
import com.success.system.dto.EnteringDTO;
import com.success.system.mapper.EmployeeMapper;
import com.success.system.mapper.MealMapper;
import com.success.system.mapper.TenantMapper;
import com.success.system.service.ITenantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wolf
 * @since 2020-02-21
 */
@Service
public class TenantServiceImpl extends ServiceImpl<TenantMapper, Tenant> implements ITenantService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Autowired
    private MealMapper mealMapper;
    @Override
    public void entering(EnteringDTO entering) {
        Date date = new Date();

        entering.getTenant().setRegisterTime(date);
        entering.getTenant().setState(true);
        baseMapper.insert(entering.getTenant());

        Long id = entering.getTenant().getId();
        entering.getEmployee().setInputTime(date);
        entering.getEmployee().setState(0);
        entering.getEmployee().setTenantId(id);
        entering.getEmployee().setType(3);
        employeeMapper.insert(entering.getEmployee());

        mealMapper.insertRelationMealAndTenant(entering.getMealId(),id,0);
    }
}
